package tools;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @Author 王志康
 * @Date 2021/8/31 10:24
 * @Version 1.0.0
 */
public class UtilJDBC {
    public static String url = "jdbc:mysql://localhost:3306/Discipline";
    public static String userName = "root";
    public static String userPassword = "wzk1397030895";
    public static Connection connection;

    /**
     * 开启数据库连接
     */
    public static void basic() {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection = DriverManager.getConnection(url, userName, userPassword);
        } catch (SQLException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 关闭数据库连接
     */
    public static void close() {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
